package com.aqgj.User.bean;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;

import com.aqgj.Organization.bean.Organization;
import com.aqgj.Role.bean.Role;
import com.aqgj.util.BaseEntity;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "sys_user")
    //@JsonIgnoreProperties({"roles"})
public class User implements BaseEntity {

    private String id;//ID
    private String account;//账户
    private String password;//密码
    private String salt;//密码加密盐
    private String userType;//用户类别(1普通用户，2管理员)
    private String status;//状态（1正常，2冻结）
    private String name;//用户名称
    private String transportId;//公司id
    private String telPhone;//手机号码
    private String remark;//备注
    private Date currTime;//创建时间
    private Organization organization;
    private Set<Role> roles = new HashSet<Role>();  ;

    public void setId(String value) {
        this.id = value;
    }

    public void setAccount(String value) {
        this.account = value;
    }

    public void setPassword(String value) {
        this.password = value;
    }

    public void setStatus(String value) {
        this.status = value;
    }

    public void setName(String value) {
        this.name = value;
    }

    public void setTransportId(String transportId) { this.transportId = transportId; }

    public void setTelPhone(String telPhone) {  this.telPhone = telPhone; }

    public void setRemark(String remark) {   this.remark = remark; }

    public void setCurrTime(Date currTime) { this.currTime = currTime;  }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Column(name = "id", unique = true, nullable = false, insertable = true, updatable = true, length = 32)
    public String getId() {
        return this.id;
    }

    @Column(name = "account", unique = false, nullable = true, insertable = true, updatable = true, length = 64)
    public String getAccount() {
        return this.account;
    }

    @Column(name = "password", unique = false, nullable = true, insertable = true, updatable = true, length = 128)
    public String getPassword() {
        return this.password;
    }

    @Column(name = "status", unique = false, nullable = true, insertable = true, updatable = true, length = 8)
    public String getStatus() {
        return this.status;
    }

    @Column(name = "name", unique = false, nullable = true, insertable = true, updatable = true, length = 64)
    public String getName() {
        return this.name;
    }

    @Column(name = "transport_id", unique = false, nullable = true, insertable = true, updatable = true, length = 32)
    public String getTransportId() { return transportId; }

    @Column(name = "telphone", unique = false, nullable = true, insertable = true, updatable = true, length = 11)
    public String getTelPhone() { return telPhone;  }

    @Column(name = "remark", unique = false, nullable = true, insertable = true, updatable = false, length = 256)
    public String getRemark() {  return remark;}

    @Column(name = "curr_time", unique = false, nullable = true, insertable = true, updatable = false, length = 0)
    public Date getCurrTime() {   return currTime;  }

    @Column(name = "salt", unique = false, nullable = true, insertable = true, updatable = false, length = 36)
    public String getSalt() {
        return salt;
    }

    @Column(name = "user_type", unique = false, nullable = true, insertable = true, updatable = true, length = 4)
    public String getUserType() {
        return userType;
    }

    @ManyToOne
    @JoinColumn(name="organization_id")
    public Organization getOrganization() {
        return organization;
    }

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name="user_role",
            joinColumns={@JoinColumn(name="user_id")},
            inverseJoinColumns={@JoinColumn(name="role_id")}
    )
    public Set<Role> getRoles() {
        return roles;
    }


}
